﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using RedLockNet;

namespace Jack.RedisLib
{
    public interface IRedisLock : IDisposable
    {
        /// <summary>
        /// 创建红锁
        /// </summary>
        /// <param name="resource">锁定的资源标识</param>
        /// <param name="expireTime">锁的过期时间（防止锁未释放，导致死锁）</param>
        /// <returns>红锁</returns>
        Task<IRedLock> CreateLockAsync(string resource, TimeSpan expireTime);
        /// <summary>
        /// 创建红锁
        /// </summary>
        /// <param name="resource">锁定的资源标识</param>
        /// <param name="expireTime">锁的过期时间（防止锁未释放，导致死锁）</param>
        /// <param name="waitTime">等待获取锁的最长时间，超时会直接返回</param>
        /// <param name="retryTime">重试获取锁的时间间隔</param>
        /// <param name="cancellationToken">取消等待的令牌</param>
        /// <returns>红锁</returns>
        Task<IRedLock> CreateLockAsync(string resource, TimeSpan expireTime, TimeSpan waitTime, TimeSpan retryTime, CancellationToken cancellationToken = default);
    }
}
